package com.hiabr.iep.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hiabr.iep.admin.api.UserService;
import com.hiabr.iep.admin.po.User;
import com.hiabr.iep.admin.vo.req.UserPageReq;
import com.hiabr.iep.admin.vo.resp.UserRespVo;
import com.hiabr.iep.common.domain.vo.resp.BaseResponse;
import com.hiabr.iep.common.domain.vo.resp.PageResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author jie huang
 * @since 2023-06-28
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Lazy
    @Resource
    private UserService userService;


    /**
     * 分页查询用户
     *
     * @param req
     * @return {@link BaseResponse}<{@link PageResponse}<{@link UserRespVo}>>
     */
    @GetMapping("/page")
    public BaseResponse<PageResponse<UserRespVo>> page(@Valid UserPageReq req) {
        IPage<User> pos = userService.pageUser(req);
        PageResponse<UserRespVo> page = PageResponse.page(pos, UserRespVo.class);
        return BaseResponse.ok(page);
    }
}
